package com.kevin.sort;

/**
 *
 * @function: 交换排序 之 冒泡排序
 *
 * @auther: Kevin
 * @date: 16:19 2019/12/3
 */
public class BubbleSortTest {
    public static void main(String[] args) {
        int arr[] = {6,7,5,3,1,2,0};
        out(arr);
        bubbleSort(arr);
        out(arr);

        int i = Integer.parseInt("1234");
        System.out.println(i);

    }

    private static void bubbleSort(int[] arr) {
        for (int i=0;i<arr.length;i++) {
            for (int j=i+1;j<arr.length-1;j++) {
                if (arr[i] > arr[j]) {
                    swap(arr,i,j);
                }
            }
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    private static void out(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != arr[arr.length-1]){
                System.out.print(arr[i]+",");
            }else{
                System.out.println(arr[i]);
            }
        }
    }
}